package com.gitee.wsl.compose.modifier

import androidx.annotation.FloatRange
import androidx.compose.foundation.background
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.BlurredEdgeTreatment
import androidx.compose.ui.draw.blur
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.Dp

interface ModifierScope{
    var modifier: Modifier
}


interface ModifierStyleScope:ModifierScope{
    fun background(
        color: Color,
        shape: Shape = RectangleShape
    ) {
        modifier = modifier.background(color, shape)
    }

    fun background(
        brush: Brush,
        shape: Shape = RectangleShape,
        @FloatRange(from = 0.0, to = 1.0)
        alpha: Float = 1.0f
    ){
        modifier = modifier.background(brush, shape, alpha)

    }

    fun blur(
        radiusX: Dp,
        radiusY: Dp,
        edgeTreatment: BlurredEdgeTreatment = BlurredEdgeTreatment.Rectangle,
    ){
        modifier = modifier.blur(radiusX, radiusY, edgeTreatment)
    }

    fun blur(
        radius: Dp,
        edgeTreatment: BlurredEdgeTreatment = BlurredEdgeTreatment.Rectangle
    ){
        modifier = modifier.blur(radius, edgeTreatment)
    }

}

class ModifierStyleScopeImp(override var modifier: Modifier):ModifierStyleScope

fun Modifier.style(block:ModifierStyleScope.()->Unit):Modifier = ModifierStyleScopeImp(this).apply(block).modifier

